Even in ancient
times, the Egyptians knew that a triangle with sides 3, 4,
and 5 is a right triangle, with its right angle being the largest
one. Determine whether other triangles also have this property.
Input. Consists of
several test cases, ending with the line 0 0 0. Each test case contains
three positive integers – the lengths of the sides of a triangle. All numbers
do not exceed 30000.
Output. For each test
case, print in a separate line “right” if the triangle is right-angled, or
“wrong” otherwise.
Sample
input |
Sample
output |
6 8 10 25 52 60 5 12 13 0 0 0 |
right wrong right |
loops
Let a, b, c be the sides of a triangle. A triangle is right-angled
if one of the following conditions holds:
·
a2 = b2 + c2 (the hypotenuse is side a)
·
b2 = a2 + c2 (the hypotenuse is side b)
·
ñ2 = a2 + b2 (the hypotenuse is side ñ)
Read the input data until
the end of the file.
while(scanf("%d %d %d",&a,&b,&c))
{
If three zeros are encountered, terminate the program.
if (a + b + c == 0) break;
Check whether the triangle is a right triangle. Print the result
accordingly.
if ((a * a + b * b == c * c) ||
(a * a + c * c
== b * b) ||
(b * b + c * c
== a * a))
puts("right");
else
puts("wrong");
}
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new
Scanner(System.in);
while(con.hasNextInt())
{
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
if (a + b + c == 0) break;
if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a))
System.out.println("right");
else
System.out.println("wrong");
}
con.close();
}
}
Read the input data until
the end of the file.
while True:
a, b, c = map(int, input().split())
If three zeros are encountered, terminate the program.
if a + b + c == 0: break
Check whether the triangle is a right triangle. Print the result
accordingly.
if (a * a + b * b == c * c) or (a * a + c * c == b *
b) or
(b * b + c * c == a *
a):
print("right");
else:
print("wrong")